<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>修改广告位</title>
    <link href="../../css/admin/style.css" rel="stylesheet" type="text/css" />
    <script src="../../js/jquery-1.8.3.min.js" type="text/javascript"></script >
    <script src="../../js/ajaxfileupload.js" type="text/javascript"></script>
    <script>
        $(function (){
            var id = location.search.split("=")[1];
            $("#id").val(id);
            $.get("../../newstype/getnewstypeById",{id:id},function (res){
                $("input[name='journame']").val(res.data.journame);
            },"json")
        })
        var check = 0;
        function checkName(){
            var journame = $("input[name='journame']").val();
            if (journame == ""){
                $("#checkSpan").html("新闻类型不能为空");
                check = 1;
                return ;
            }
            $.get("../../newstype/checkName",{journame:journame},function (res){
                if (res.code == 202){
                    window.parent.location.replace("../login.html");
                }else if (res.code == 500){
                    alert(res.msg);
                }else if (res.code == 201){
                    $("#checkSpan").html(res.msg);
                    check = 1;
                }else {
                    $("#checkSpan").html(res.msg);
                    check = 0;
                }
            })
        }
        function toUpdate(){
            if (check==1){
                alert("该新闻类型已存在，请重新输入或返回！");
                return ;
            }
            $.post("../../newstype/updateNewsType",$("#formId").serialize(),function(res){
                if (res.code == 202){
                    window.parent.location.replace("../login.html");
                }else if (res.code == 500){
                    alert(res.msg);
                }else {
                    alert(res.msg);
                    location.replace("list.html");
                }
            })
        }


    </script>
</head>
<body>
<form id="formId">
    <input type="hidden" id="id" name="id">
    <div class="formbody">
        <div class="formtitle"><span>基本信息</span></div>
        <ul class="forminfo">
            <li>
                <label>新闻类型名</label>
                <input name="journame" type="text" class="dfinput" onblur="checkName()"/>
                <span id="checkSpan"></span>
            </li>

            <li>
                <input name="" type="button"  value="确认修改" onclick="toUpdate()"/>
            </li>
        </ul>
    </div>
</form>
</body>
</html>